package com.web.controller.author;

import com.bean.Category;
import com.bean.News;
import com.bean.Users;
import com.service.DataBookService;
import com.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import sun.rmi.runtime.Log;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller("authorNewsController")
public class NewsController {
  @Autowired
  @Qualifier("dataBookService")
  private DataBookService dataBookService;

  //此步不可少
  @Autowired
  @Qualifier("newsService")
  private NewsService newsService;



  @RequestMapping(value = "/manage/author/news/publish",method = RequestMethod.GET)
    public String publish(Map map){
      //查出下拉框需要的数据
      List<Category> categories = dataBookService.findALLCategories();
      map.put("categories",categories);

      System.out.println("测试有没有更新");

      return "/manage/author/news/publish";

  }

  @RequestMapping(value = "/manage/author/news/publish",method = RequestMethod.POST)
  public String publish(News news, HttpSession session){

    Users user = (Users) session.getAttribute("user");
    news.setUsersId(user.getId());//填充发布人
    System.out.println("问题问题问题：：：：1");
    newsService.publish(news);
    System.out.println("问题问题问题：：：：2");
    return "/manage/author/news/publish";

  }
//修改
  @RequestMapping(value = "/manage/author/news/find",method = RequestMethod.GET)
  public String find(@RequestParam Map params,Map model, HttpSession session){
    Users user = (Users) session.getAttribute("user");

    params.put("UsersId",user.getId());//写入用户条件

    List<News> list = newsService.list(params);

    model.put("list",list);

    return "/manage/author/news/list";

  }







  public DataBookService getDataBookService() {
    return dataBookService;
  }

  public void setDataBookService(DataBookService dataBookService) {
    this.dataBookService = dataBookService;
  }

  public NewsService getNewsService() {
    return newsService;
  }

  public void setNewsService(NewsService newsService) {
    this.newsService = newsService;
  }
}
